package com.wisezone.studentmanger.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 实现页面间跳转
 * html->serlvet->html
 *
 * @author zhousir
 * @创建时间 2017年10月11日
 */
public class LoginServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");//解决post请求乱码;
		response.setContentType("text/html;charset=UTF-8"); //解决响应乱码
		
//		int a = 8/0;
		
		String userName = request.getParameter("username");
		String passWord = request.getParameter("password");
		System.out.println(userName+"  "+passWord);
		
		if("admin".equals(userName) && "123".equals(passWord)){
//			response.sendRedirect("success.html"); //重定向到指定页面
			request.getRequestDispatcher("success.html").forward(request, response);//转发
		}else{
			response.sendRedirect("fail.html");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
